#! /bin/sh

name=gcc
from_source=gcc-host
clean_workdirs=no
revision=1
imagedeps="experimental:build-essential"
hostdeps="pkg-config"
hostrundeps="binutils"
deps="mlibc-headers"

configure() {
    cp -rp "${source_dir}"/. ./
    mkdir -p build && cd build

        CFLAGS="$HOST_CFLAGS" \
        CXXFLAGS="$HOST_CXXFLAGS" \
        LDFLAGS="$HOST_LDFLAGS" \
        CFLAGS_FOR_TARGET="$TARGET_CFLAGS" \
        CXXFLAGS_FOR_TARGET="$TARGET_CXXFLAGS" \
    ../configure \
        --prefix="${prefix}" \
        --target=${OS_TRIPLET} \
        --with-sysroot="${sysroot_dir}" \
        --disable-nls \
        --with-linker-hash-style=gnu \
        --enable-linker-build-id \
        --enable-languages=c,c++,lto \
        --enable-default-pie \
        --enable-default-ssp \
        --disable-multilib \
        --enable-initfini-array \
        --enable-shared \
        --enable-host-shared
}

build() {
    cd build
    make -j${parallelism} all-gcc
}

package() {
    cd build
    DESTDIR="${dest_dir}" make install-gcc

        strip_command=strip \
    post_package_strip
}
